
package org.come.Jpanel;

import com.tool.tcpimg.ChatBox;
import com.tool.tcpimg.UIUtils;
import io.netty.util.internal.StringUtil;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import org.come.socket.DownLoadTxt;

public class GGJpanel extends JPanel {
    ChatBox box = new ChatBox();
    private ImageIcon icon;
    private static JLabel labtext1,labtext2;
    public GGJpanel() {
        this.box = new ChatBox();
        List<String> sb = this.getGG();

        for(int i = 0; i < sb.size(); ++i) {
            this.box.addText((String)sb.get(i), 600, UIUtils.TEXT_MSG);
        }

        this.setPreferredSize(new Dimension(682, 475));
        this.setBackground(UIUtils.Color_BACK);



        Font font = new Font("楷体", Font.BOLD, 25);
        labtext1 = new JLabel();
        labtext1.setForeground(Color.yellow);
        labtext1.setFont(font);
        labtext1.setBounds(150, 450, 280, 30);
        labtext1.setText("游戏公告");
        this.add(labtext1);
    }

    public static void main(String[] args) {
        List<String> list = (new GGJpanel()).getGG();
        //system.out.println(list);
    }

    public List<String> getGG() {
        String v = DownLoadTxt.getDownLoadTxt().GetServerTxt("gg.txt");
        if (v != null && v.length() != 0) {
            String[] vs = v.split("\r\n");
            if (vs.length == 1) {
                vs = v.split("\n");
            }

            for(int i = 0; i < vs.length; ++i) {
                if (StringUtil.isNullOrEmpty(vs[i])) {
                    vs[i] = " ";
                }
            }

            return Arrays.asList(vs);
        } else {
            return new ArrayList<>();
        }
    }

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        if (this.icon == null) {
            this.icon = new ImageIcon("inkImg/old/1/gg.png");
        }

        g.drawImage(this.icon.getImage(), 0, 0, 682, 475, this);
        Graphics g22 = g.create(50, 45, 675, 475);
        this.box.paint(g22);
        g22.dispose();
    }
}
